package com.deyuanyun.pic.pbf.controller.dto.validata;

import org.apache.commons.beanutils.BeanUtils;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.pbf.controller.dto.DefectInfoDTO;
import com.deyuanyun.pic.pbf.service.RepairTaskService;

/**
 * 验证缺陷点的维修方法与系统中是否一致
 * 
 * @author ChenKui
 * @date 2016-02-22
 */
public class RepairTypeValidata implements ValidateInterface {

	@Override
	public <T, E,C> boolean apply(T t, E e,C c) {
	    //if(true){return true;}
		if(ObjectUtil.isNotNullEmpty(t)){
            try {
                String defectInfoCode = (String)BeanUtils.getProperty(c,"defectInfoCode");
                
                RepairTaskService repairTaskService = (RepairTaskService)SpringAppliction.getBean(RepairTaskService.class);
                DefectInfoDTO defectInfo = repairTaskService.queryDefectInfoByDefectInfoCode(defectInfoCode);
                if(defectInfo == null){//此处只验证维修方法是否相同，如果无此缺陷点，则不验证。要不然会提示维修方法与系统不符。
                    return true;
                }
                //TODO 待验证：验证缺陷点的维修方法与系统中是否一致
                return t.equals(defectInfo.getPlanRepairType());//这个虽然没判定NUll，但是我try了。
            } catch (Exception e1) {
                return false;
            }
		}
		return true;
	}

	@Override
	public String getName() {
		return null;
	}

}
